package cn.wolfcode.trip.base.domain;

import com.alibaba.druid.support.json.JSONUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 游记推荐实体类
 */

@Setter
@Getter
public class TravelCommend extends BaseDomain{

    public static final int TYPE_WEEK =1;//每周推荐
    public static final int TYPE_MONTH =2;//每月推荐
    public static final int TYPE_STRATEGY =3;//攻略推荐

    //游记id
    private Travel travel;
    //推荐的标题
    private String title;
    //副标题
    private String subTitle;
    //背景图
    private String coverUrl;

    //推荐时间表
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd" ,timezone = "GMT+8")
    private Date schedule;

    //推荐类型
    private Integer type;


    //json字符串
    public String getJsonString(){

        Map<String,Object> map=new HashMap<>();
        map.put("id",id);
        if(travel!=null){
            map.put("travelId",travel.id);
        }
        map.put("title",title);
        map.put("subTitle",subTitle);
        map.put("coverUrl",coverUrl);
        map.put("schedule",new SimpleDateFormat("yyyy-MM-dd").format(schedule));
        map.put("type",type);
        return JSONUtils.toJSONString(map);
    }

    //推荐类型的描述
    public String getTypeName(){
        String str="";
        switch (type){
            case TYPE_WEEK:
                str="每周推荐";
                break;
            case TYPE_MONTH:
                str="每月推荐";
                break;
            default:str ="攻略推荐";
        }
        return str;
    }

}